/**
* @component Search
*/

@import "@automattic/typography/styles/variables";
@import "@wordpress/base-styles/variables";
@import "@wordpress/base-styles/mixins";
@import "@wordpress/base-styles/breakpoints";

$input-z-index: 20;

.search-component {
	border-radius: 2px;
	display: flex;
	width: 60px;
	height: 51px;
	position: relative;
	align-items: center;
	// places search above filters
	z-index: 1;
	transition: all 0.15s ease-in-out;

	.search-component__left-icon-container {
		min-width: 32px;
		svg {
			fill: var( --color-neutral-10 );
		}
	}

	input.search-component__input[type="search"] {
		flex: 1 1 auto;
		z-index: $input-z-index;
		top: 0;
		border: none;
		height: 100%;
		background: var(--color-surface);
		appearance: none;
		border-radius: 0;
		box-sizing: border-box;
		padding: 0;
		-webkit-appearance: none;

		&::-webkit-search-cancel-button {
			-webkit-appearance: none;
		}

		&:disabled {
			background: var(--color-surface);
		}

		&:focus {
			box-shadow: none;
			border: none;
			outline: none;

			&:hover {
				border: none;
				box-shadow: none;
				outline: none;
			}
		}
	}

	.search-component__input-fade .search-component__text-overlay {
		color: transparent;
		position: absolute;
		pointer-events: none;
		white-space: nowrap;
		display: flex;
		align-items: center;
		flex: 1 1 auto;
		overflow: hidden;
		font-size: inherit;
		font-family: inherit;
		width: 100%;
		height: 100%;
		top: 1px;
		left: 0;
		z-index: $input-z-index + 1;
		padding-left: 5px;
	}

	&__icon-navigation {
		flex: 0 0 auto;
		display: flex;
		align-items: center;
		background-color: var(--color-surface);
		height: 100%;

		.accessible-focus &:focus {
			box-shadow: inset 0 0 0 2px var(--color-primary-light);
			position: relative;
			z-index: 9999;
		}
	}

	&__open-icon,
	&__close-icon {
		flex: 0 0 auto;
		width: 19px;
		z-index: 20;
		color: var(--color-primary);
		cursor: pointer;

		@include break-mobile {
			width: 50px;
		}
	}

	&__open-icon:hover {
		color: var(--color-neutral-60);
	}

	&__close-icon {
		color: var(--color-neutral-60);
		opacity: 0;
		transition: opacity 0.2s ease-in;
	}

	&.is-open.has-focus {
		border-color: var(--color-primary);
		box-shadow: 0 0 0 2px var(--color-primary);

		&:hover {
			box-shadow: 0 0 0 2px var(--color-primary);
		}
	}

	&:not(.is-open) input.search-component__input[type="search"] {
		display: none;
	}

	&.is-expanded-to-container {
		margin-bottom: 0;
		position: absolute;
		display: flex;
		height: 100%;
		top: 0;
		right: 0;

		.search-component__input-fade {
			position: relative;
			flex: 0 0 auto;
			display: flex;
			align-items: center;
		}

		.search-component__input {
			flex: 1 1 auto;
			display: flex;
		}
	}

	&.is-compact,
	&.is-expanded-to-container.is-compact {
		height: 36px;
		justify-content: end;
		.search-component__input {
			display: flex;
			align-items: center;
			height: 36px;
			font-size: $font-body-extra-small;
		}

		.search-component__open-icon {
			margin: 0 4px 0 8px;
			width: 18px;
		}

		.search-component__close-icon {
			width: 18px;
			margin-right: 8px;
		}
	}

	.components-spinner {
		display: none;
		margin: 5px 11px;
	}

	.components-button {
		padding: 8px;

		@include break-mobile {
			padding: 0;
		}

		&:focus {
			z-index: 9999;
		}
	}

	&.is-open {
		background-color: var(--color-surface, $white);
		width: 100%;

		.search-component__open-icon {
			color: var(--color-neutral-60);
		}

		.search-component__close-icon {
			display: inline-block;
		}

		.search-component__input,
		.search-component__close-icon {
			opacity: 1;
		}

		input.search-component__input[type="search"] {
			font-size: inherit;
			display: block;
		}

		.search-component__input-fade {
			display: flex;
			align-items: center;
			border-radius: 0;
			flex: 1 1 auto;
			height: 100%;
			position: relative;
			font-size: $font-body;

			&::before {
				@include long-content-fade( $direction: right, $size: 32px, $z-index: $input-z-index + 2, $color: var( --color-surface ) );
				border-radius: inherit;
			}

			&.rtl {
				&::before {
					@include long-content-fade(
						$direction: left,
						$size: 32px,
						$z-index: $input-z-index + 2,
						$color: var( --color-surface )
					);
					border-radius: inherit;
				}
			}

			padding-left: 8px;
		}
	}

	// Removes the fade overlay when the search is open and focused
	&.has-focus {
		.search-component__input-fade {

			&::before {
				display: none;
			}

			&.rtl {
				&::before {
					display: none;
				}
			}
		}
	}

	&.has-open-icon {
		.search-component__input-fade {
			padding-left: 0;
		}
	}

	&.is-searching {
		.search-component__open-icon {
			display: none;
		}

		.components-spinner {
			flex: 0 0 auto;
			display: flex;
			z-index: 20;
		}
	}
}
